import QtQuick 2.12
import QtQuick.Window 2.12
import QtQuick.Controls 2.5

Window {
    id:root
    visible: true
    width: 640
    height: 480
    title: qsTr("FramelessWindow")

    /**
      TODO：
      1. 任务栏区域限制
      2. 最大化、最小化会闪
      3. 多屏拖拽
      4. 侧边栏拉伸
      */

    flags: Qt.FramelessWindowHint
    color: "transparent"

    property int titleBarHeight: 30;

    Component {
        id:m_compTitleRect

        Rectangle {
            color: "gray"
            property var testFlag : true;
        }
    }

    Component {
        id : m_compMainView
        Rectangle {
            id:m_rect

            BCTitleBar {
                id:m_title
                width: parent.width
                height: titleBarHeight
                anchors.top: parent.top

                windowRef: root

                plRectangle: m_compTitleRect

                Button {
                    id: m_x
                    height: parent.height
                    width: height
                    anchors.right: parent.right
                    anchors.rightMargin: 5
                    font.pointSize: 24
                    text: qsTr("X")
                    onClicked: {
                        root.close();
                    }
                }

                Button {
                    id: m_max
                    height: parent.height
                    width: height
                    anchors.right: m_x.left
                    anchors.rightMargin: 10
                    font.pointSize: 24
                    text: qsTr("O")
                    onClicked: {
                        /* 正常化窗口会蹦一下 */
                        root.visibility = root.visibility === Window.FullScreen ? Window.Windowed : Window.FullScreen;
                    }
                }

                Button {
                    id: m_min
                    height: parent.height
                    width: height
                    anchors.right: m_max.left
                    anchors.rightMargin: 10
                    font.pointSize: 24
                    text: qsTr("-")
                    onClicked: {
                        root.visibility  = Window.Minimized
                    }
                }
            }
        }
    }


    BCFramelessRectangle {
        plRectangle: m_compMainView

        parentRef: root

    }
}
